//
//  AppDelegate.m
//  Car
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "AppDelegate.h"
#import "YZLSearchCarViewController.h"
#import "YZLHomePageViewController.h"
#import "DiscussViewController.h"
#import "UMSocial.h"
#import "YZLCarRedioViewController.h"
#import "YZLMyViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface AppDelegate ()

@property (nonatomic, strong) UITabBarController *tb;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //设置后台播放会话
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    [session setActive:YES error:nil];
    
    self.tb = [[UITabBarController alloc] init];
    self.window.rootViewController = self.tb;
    
    /* 首页 */
    YZLHomePageViewController *homePage = [[YZLHomePageViewController alloc] init];
    UINavigationController *homePageNavi = [[UINavigationController alloc] initWithRootViewController:homePage];
    homePage.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"shouye"] tag:100];
    
    
    //论坛
    DiscussViewController *discuss = [DiscussViewController shareDiscussViewController];
    UINavigationController *discussNavi = [[UINavigationController alloc] initWithRootViewController:discuss];
    discuss.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"论坛" image:[UIImage imageNamed:@"论坛1"] tag:200];
    
    [UMSocialData setAppKey:@"561cb0a267e58ed7c2004b02"];
    
    //找车
    YZLSearchCarViewController *search = [[YZLSearchCarViewController alloc] init];
    UINavigationController *searchNavi = [[UINavigationController alloc] initWithRootViewController:search];
    search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"找车" image:[UIImage imageNamed:@"找车"] tag:300];
    
    //电台
    YZLCarRedioViewController *redio = [[YZLCarRedioViewController alloc] init];
    UINavigationController *redioNavi = [[UINavigationController alloc] initWithRootViewController:redio];
    redio.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"汽车电台" image:[UIImage imageNamed:@"电台"] tag:400];
    
    //我的
    YZLMyViewController *my = [[YZLMyViewController alloc] init];
    UINavigationController *myNavi = [[UINavigationController alloc] initWithRootViewController:my];
    my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"我的"] tag:500];
    
    self.tb.viewControllers = @[homePageNavi, discussNavi, searchNavi, redioNavi, myNavi];
    self.tb.tabBar.barTintColor = [UIColor colorWithRed:127 / 255.f green:194 / 255.f blue:253/ 255.f alpha:1.000];
    self.tb.tabBar.backgroundColor = [UIColor colorWithRed:127 / 255.f green:194 / 255.f blue:253/ 255.f alpha:1.000];
    
    //改变navigationBar颜色和字体大小
    UINavigationBar *bar = [UINavigationBar appearance];
    NSDictionary *dict = @{
                           NSForegroundColorAttributeName:[UIColor blackColor],
                           NSFontAttributeName:[UIFont systemFontOfSize:18]
                           
                           };
    [bar setTitleTextAttributes:dict];
    
    [bar setTintColor:[UIColor blackColor]];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    
    //开启后台播放
    [application beginBackgroundTaskWithExpirationHandler:nil];
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
